package com.bwie.service;

import com.bwie.bean.Article;
import com.bwie.bean.Tag;
import com.bwie.dao.ArticleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleDao articleDao;

    @Override
    public List<Article> list(Map map) {
        return articleDao.list(map);
    }

    @Override
    public List<Tag> listTag() {
        return articleDao.listTag();
    }

    @Override
    public int delAll(String aid) {
        //删除主表
        int a=articleDao.delArtcle(aid);
        //删除中间表
        articleDao.delAt(aid);

        return a;
    }

    @Override
    public int add(Article article, Integer[] tids) {
        //添加主表
        int a=articleDao.addArticle(article);
        //添加中间表
        Map map = new HashMap();
        map.put("aid",article.getAid());
        map.put("tids",tids);
        articleDao.addAt(map);
        return a;
    }

    @Override
    public int update(Article article, Integer[] tids) {
        int a=articleDao.update(article);
        //删除中间表
        articleDao.delAta(article.getAid());
        Map map = new HashMap();
        map.put("aid",article.getAid());
        map.put("tids",tids);
        articleDao.addAt(map);
        return a;
    }

    @Override
    public Article listHui(Integer aid) {
        return articleDao.listHui(aid);
    }
}
